namespace YM{
    export class IConfig{
        protected _id:any;
        public get id():any{
            return this._id;
        }
        public set id(value:any){
            this._id=value;
        }
    }
    export abstract class ACategory{
        protected configDic:Map<any,IConfig>=new Map<any,IConfig>(); 
        public init():void{

        }
        public get(id:any):IConfig{
            return this.configDic.get(id.toString());
        }
        public getOne():IConfig{
            let config:IConfig;
            for (const iterator of this.configDic) {
                config=iterator[1];
                break;
            }
            return config;
        }
        public getAll(){
            return Array.from(this.configDic.values());
        }
    }
    export class ConfigMgr{
        private allConfig:Map<{new()},ACategory> = new Map<{new()}, ACategory>();
        public init():void{
            for (const configType of configTypes) {
                let cate=new configType.cateCon();
                this.allConfig.set(configType.type,cate);

                if(configType.initState){
                    cate.init();
                }
            }
        }
        public initConfig(configCon:new()=>any){
            for (const configType of configTypes) {
                if(configCon==configType.type){
                    if(configType.initState){
                        let cate=new configType.cateCon();
                        this.allConfig.set(configType.type,cate);
                        cate.init();
                    }
                }
            }
        }
        public getOne<T extends IConfig>(type:{new():T}):T{
            let cate=this.allConfig.get(type);
            if(cate==null){
                return null;
            }
            let config=cate.getOne();
            return config as T;
        }
        public getAll<T extends IConfig>(type:{new():T}){
            let cate=this.allConfig.get(type);
            if(cate==null){
                return null;
            }
            let configs=cate.getAll();
            return configs as T[];
        }
        public get<T extends IConfig>(type:{new():T},id:any):T{
            let cate=this.allConfig.get(type);
            if(cate==null){
                return null;
            }
            let config=cate.get(id);
            return config as T;
        }
    }
}
